package com.gsafety.wellsfort.controller.knowledge;

import com.gsafety.wellsfort.common.util.ApiResponse;
import com.gsafety.wellsfort.domain.dto.exam.*;
import com.gsafety.wellsfort.domain.dto.ids.ExamIdDTO;
import com.gsafety.wellsfort.domain.vo.ExamVO;
import com.gsafety.wellsfort.domain.vo.QuestionVO;
import com.gsafety.wellsfort.service.knowledge.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "试卷管理",description = "试卷管理接口")
@RestController
@Slf4j
@RequestMapping("/api/exam")
public class ExamController {
    @Autowired
    private ExamService examService;
    @ApiOperation(value="保存试卷基本信息")
    @PostMapping("/save-baseinfo")
    public ApiResponse<ExamBaseInfoDTO> saveBaseInfo(@RequestBody ExamBaseInfoDTO workBaseInfoDTO){
        return examService.saveBaseInfo(workBaseInfoDTO);
    }
    @ApiOperation(value="保存试卷配置信息")
    @PostMapping("/save-examsetting")
    public ApiResponse<ExamSettingDTO> saveBaseInfo(@RequestBody ExamSettingDTO workSettingDTO){
        return examService.saveWorkSetting(workSettingDTO);
    }
    @ApiOperation(value="从试卷中移除一道试题")
    @PostMapping("/remove-question")
    public ApiResponse removeQuestion(@RequestBody ExamIdDTO idDTO ){
        return examService.removeQuestion(idDTO.getExamQuId());
    }

    @ApiOperation(value="给试卷添加试题")
    @PostMapping("/add-question")
    public ApiResponse<ExamQuDTO> addQuestion(@RequestBody ExamQuDTO examQuDTO){
        return examService.addQuestion(examQuDTO);
    }

    @ApiOperation(value="编辑预览试卷")
    @PostMapping("/get-exam")
    public ApiResponse<ExamVO> getExam(@RequestBody ExamIdDTO idDTO){
        return examService.getExam(idDTO.getExamId());
    }
    @ApiOperation(value="查询试卷列表")
    @PostMapping("/exam-list")
    public ApiResponse<List<ExamVO>> findWorkByPageParams(@RequestBody ExamQueryDTO examQuDtoParams){
        return examService.findExamByPageParams(examQuDtoParams);
    }
    @ApiOperation(value="根据类型分页获取试卷题目列表")
    @PostMapping("/examQu-list")
    public ApiResponse<List<QuestionVO>> findQuestionByPageParams(@RequestBody ExamQuQueryDTO examQuDtoParams){
        return examService.findQuestionByPageParams(examQuDtoParams);
    }
    @ApiOperation(value="未添加到试卷里的题目列表")
    @PostMapping("/addQu-list")
    public ApiResponse<List<QuestionVO>> findAddQuestionByPageParams(@RequestBody ExamQuQueryDTO examQuDtoParams){
        return examService.findAddQuestionByParam(examQuDtoParams);
    }

    @ApiOperation(value="删除试卷")
    @PostMapping("/del-exam")
    public ApiResponse deleteExam(@RequestBody ExamIdDTO idDTO){
        return examService.deleteExam(idDTO.getExamId());
    }

}
